﻿// Deep Earth is a community project available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warranty – Use at your own risk
// View the project and the latest code at http://DeepEarth.codeplex.com/

using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Media;
using GisSharpBlog.NetTopologySuite.Geometries;

namespace DeepEarth.Client.MapControl.Geometries
{
    public class LineStringControl : PathControlBase
    {
        public LineStringControl()
            : base(new LineString(null))
        {
            Stroke = new SolidColorBrush(Colors.Black);
            StrokeThickness = 1;
        }

        internal override void UpdateGeometry()
        {
            GeometryItem = new LineString(Locations.Select(location => new Coordinate(location.Longitude, location.Latitude)).ToArray());
        }

        internal override void UpdateLocation()
        {
            if (GeometryItem != null)
            {
                Locations = new ObservableCollection<Location>(((LineString)GeometryItem).Coordinates.Select(coordinate => new Location { Longitude = coordinate.X, Latitude = coordinate.Y }).ToList());
                Refresh();
            }
        }

        public override bool IsClosed
        {
            get { return false; }
        }
    }
}